import ij.IJ;
import ij.ImagePlus;
import ij.plugin.filter.PlugInFilter;
import ij.process.ImageProcessor;

import java.awt.Point;
import java.util.List;

public class Trajectory_ListAll implements PlugInFilter {
	
	ImagePlus origImage = null;
	
	public int setup(String arg, ImagePlus img) { 
    	origImage = img;
		return DOES_RGB; 
	}
	
	@SuppressWarnings("unchecked")
	public void run(ImageProcessor ip) {
		String PROPKEY = TrajectoryUtils.PROPKEY;	// the key to this property
		List<Point[]> trajList = (List<Point[]>) origImage.getProperty(PROPKEY);
		if (trajList == null) {
			IJ.error("No trajectories found!");
			return;
		}
		
		int[][][] trajArray = TrajectoryUtils.makeTrajectoryArray(trajList);
		if (trajArray == null) {
			IJ.error("Some trajectories are too short (<3)!");
			return;
		}
		
		// original trajectories
		TrajectoryUtils.printTrajectoryArray(trajArray,"originalTrajectories");
		
		// scramble trajectories if user wants to:
		if (IJ.showMessageWithCancel("Trajectory_ListAll","Show scrambled trajectories?")) {
			TrajectoryUtils.scrambleTrajectoryArray(trajArray);
			TrajectoryUtils.printTrajectoryArray(trajArray,"scrambledTrajectories");
		}
	}
	
	/*
	trajectory k has n points (x_ik)
	i: trajectory number
	k: frame number
	d: dimension number (0,1)
	int[i][k][d] = 
		{{{1,2},{3,4} .....{8,9}}, // trajectory 0
		 {{5,2}................}}, // trajectory 1
		}
	 */
}
	
